package com.zhny.sensor.service;

import com.zhny.sensor.dao.PoultryCategoryRepository;
import com.zhny.sensor.entity.PoultryCategory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Auther: zhy
 * @Date: 2019/11/22
 * @Description: 禽类品种管理服务
 */
@Service
public class PoultryCategoryService {

    @Autowired
    private PoultryCategoryRepository poultryCategoryRepository;

    /**
     * 查询屠宰场所属的所有禽类品种信息
     *
     * @param createBy 所属屠宰场
     * @return List<PoultryCategory>
     */
    public List<PoultryCategory> getPoultryCategoryByCreate(String createBy) {
        return poultryCategoryRepository.findAllByCreateBy(createBy);
    }
    /**
     * 根据屠宰场id查询屠宰场所属的所有禽类品种信息  2020/12/1
     *
     * @param slaughterHouseId 所属屠宰场
     * @return List<PoultryCategory>
     */
    public List<PoultryCategory> getPoultryCategoryBySlaughterHouseId(String slaughterHouseId) {
        return poultryCategoryRepository.findAllBySlaughterHouseId(slaughterHouseId);
    }
    /**
     * 根据家禽父类id查询子类
     *
     * @param parentId 禽类父类id
     * @return List<PoultryCategory>
     */
    public List<PoultryCategory> getPoultryCategoryByParentId(String parentId) {
        return poultryCategoryRepository.findAllByParentId(parentId);
    }


    /**
     * 查询屠宰场大类编号写对应的子列表信息
     *
     * @param poultryCategoryNumber 大类编号
     * @param createBy 屠宰场管理员id
     * @return List<PoultryCategory>
     */
    public List<PoultryCategory> getSubPoultryCategory(int poultryCategoryNumber, String createBy) {
        return poultryCategoryRepository.findAllByNumberAndCreateBy(poultryCategoryNumber + "",createBy );
    }

    public List<PoultryCategory> getPoultryCategoryByStallsId(String stallsId) {
        return poultryCategoryRepository.findAllByStallId(stallsId);
    }
}
